<%@ include file="includes.jsp" %>

<script>
<!--
    $(document).ready(function() {
        var guessInput = document.getElementById("guess");
        if (guessInput) {
            guessInput.focus();
        }
    });

    function reject() {
    	showConfDlg(doReject);
    	return false;
    }

    function doReject() {
        $("#guessForm").attr("action", "reject_task.htm");
        $("#guessForm").submit();
    }
//-->
</script>

<div class="task-page">

<c:if test="${ (!gameContext.started) and (!gameContext.finished)}">
    <h3>
        <span style="margin-left: 10px">
            <c:if test="${! empty gameContext.start}">
                <spring:message code="messages.task.not_started"/>&nbsp;<joda:format value="${gameContext.start}" pattern="HH:mm"/>
            </c:if>
            <c:if test="${empty gameContext.start}">
                <spring:message code="messages.task.unknown"/>
            </c:if>
        </span>
    </h3>
    <br/>
</c:if>

<c:if test="${gameContext.finished}">
    <h3>
        <span style="margin-left: 10px">
            <c:if test="${! empty gameContext.end}">
                <spring:message code="messages.task.game_finished"/>&nbsp;<joda:format value="${gameContext.end}" pattern="HH:mm"/>
            </c:if>
        </span>
    </h3>
    <br/>
</c:if>

<c:if test="${(gameContext.started) and (position.finished)}">
    <h3>
        <span style="margin-left: 10px">
            <spring:message code="messages.task.team_finished"/>
        </span>
    </h3>
    <br/>
</c:if>

<c:if test="${position.team.blocked}">
    <h3>
        <span style="margin-left: 10px">
            <spring:message code="messages.task.team_blocked"/>
        </span>
    </h3>
    <br/>
</c:if>

<c:if test="${(gameContext.started) and !(position.finished) and !(position.team.blocked)}">

	<ul>
        <c:if test="${! empty message}">
	        <li style="list-style-type: none; color: red">
			    <h3>
			        <span>
			           <spring:message code="${message}" text="${message}"/>
			           <c:if test="${! empty infoString}">
			                &nbsp;${infoString}
			           </c:if>
			        </span>
			    </h3>
            </li>
		</c:if>
	    <li style="list-style-type: none">
	       <h4 style="color: grey">
	           <c:if test="${position.obtainedTask.task.codeNumber > 1}">
	               <c:if test="${position.obtainedTask.answersRemain > 1}">
	                   <spring:message code="messages.task.answers_remain"/>&nbsp;${position.obtainedTask.answersRemain}&nbsp;<spring:message code="messages.task.answers_from"/>&nbsp;${position.obtainedTask.task.codeNumber}
	               </c:if>
	               <c:if test="${position.obtainedTask.answersRemain == 1}">
	                   <spring:message code="messages.task.one_code_remain"/>&nbsp;${position.obtainedTask.task.codeNumber}
	               </c:if>
	           </c:if>
	           <c:if test="${position.obtainedTask.task.codeNumber == 1}">
                   <spring:message code="messages.task.one_total_codes"/>
               </c:if>
	       </h4>
       </li>
	</ul>                            
	<ul>
	    <li>
	        <h4><spring:message code="messages.task.task"/>
	            (<spring:message code="messages.task.task_obtained"/>&nbsp;<joda:format value="${position.obtainedTask.start}" pattern="HH:mm"/>):
	        </h4>
	        ${position.obtainedTask.task.puzzle}
	    </li>
	
	   <c:if test="${! empty position.obtainedTask.firstHint}">
		    <hr/>
		    <li>
		        <h4>
		            <spring:message code="messages.task.first_hint"/>
		                (<spring:message code="messages.task.first_hint_obtained"/>&nbsp;<joda:format value="${position.obtainedTask.firstHint}" pattern="HH:mm"/>):
		        </h4>
		           ${position.obtainedTask.task.firstHint}
		    </li>
	    </c:if>
	
	    <c:if test="${! empty position.obtainedTask.secondHint}">
		    <hr/>
		    <li>
		        <h4>
		            <spring:message code="messages.task.second_hint"/>
		                (<spring:message code="messages.task.second_hint_obtained"/>&nbsp;<joda:format value="${position.obtainedTask.secondHint}" pattern="HH:mm"/>):
		        </h4>
		        ${position.obtainedTask.task.secondHint}
		     </li>
	     </c:if>
	     <hr/>
	     <li>
	        <form action="try_guess.htm" method="POST" id="guessForm" name="guessForm">
	            <h4>
	                <spring:message code="messages.task.guess"/>
	                    (<spring:message code="messages.task.attempts_left"/>&nbsp;${position.obtainedTask.attemptsLeft}):
	            </h4>
	            <table>
	                <tr>
	                    <td><input type="text" name="guess" id="guess"></td>
	                    <td><button class="btn" style="margin-left: 5px;" onclick="this.form.submit()">
	                        <spring:message code="messages.task.try_guess"/>
	                        </button>
	                    </td>
	                    <c:if test="${! empty position.obtainedTask.firstHint}">
                            <td>
                                <button class="btn" onclick="return reject();">
                                    <spring:message code="messages.task.reject"/>
                                </button>
                            </td>
	                    </c:if>
	                </tr>
	            </table>
	        </form>
	    </li>
	</ul>

    <ul>
        <li style="list-style-type: none;">
            <hr/>
            <h4><spring:message code="messages.task.team_stat"/></h4>
	        <div class="guessed-text" style="padding-bottom: 10px; padding-left: 10px;">
	            <spring:message code="messages.gs.quessed"/>:&nbsp;${position.guessed}
	        <br></div>
	        <div class="timeout-text" style="padding-bottom: 10px; padding-left: 10px;">
	            <spring:message code="messages.gs.timeout"/>:&nbsp;${position.timeout}
	        <br/></div>
	        <div class="rejected-text" style="padding-bottom: 10px; padding-left: 10px;">
	            <spring:message code="messages.gs.rejected"/>:&nbsp;${position.rejected}
	        </div>
        </li>
    </ul>
    
 
    <ul style="list-style-type: none;">
        <c:forEach items="${context.activeNotifies}" var="notif">
            <li>
            <div class="ui-widget">
                <div class="ui-state-highlight ui-corner-all">
                    <p>
                        <span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
                        <strong>${notif.name}</strong>
                        ${notif.message}
                    </p>
                    
                </div>
            </div>
            </li>
        </c:forEach>
    </ul>

</c:if>

</div>